-
-
Couldn't load subscription status.
- Fork 1.7k
feat(core): Truncate request messages in AI integrations #17921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
| * Calculate the UTF-8 byte length of a string. | ||
| */ | ||
| const utf8Bytes = (text: string): number => { | ||
| return new TextEncoder().encode(text).length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: TextEncoder is not available in Bun Workers. I am not sure if this is something we want to support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm looks like it is https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/TextDecoder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I am officially confused: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder. Anyways - I think it is safe to assume that Bun is listed and it will work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes: #17809
Implements message truncation logic that drops oldest messages first until the payload fits within the 20KB limit. If a single message exceeds the limit, its content is truncated from the end. Supports OpenAI/Anthropic ({ role, content }) and Google GenAI ({ role, parts: [{ text }] }) message formats.